package com.pg.controller.dd;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pg.entity.cj.Jjd;
import com.pg.entity.dd.EipProductionOrder;
import com.pg.entity.dd.EipPurchaseOrder;
import com.pg.service.EipPurchaseOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 采购订单前端控制器
 * </p>
 *
 * @author likl
 * @since 2020-07-06
 */
@Api(tags = "采购订单")
@RestController
@RequestMapping("/eipPurchaseOrder")
//@Slf4j
public class EipPurchaseOrderController extends JeecgController<EipPurchaseOrder, EipPurchaseOrderService> {

    @Autowired
    private EipPurchaseOrderService eipPurchaseOrderService;

    /**
     * 获取地区数据
     *
     * @param supplierCode 供应商编码
     * @return 地图数据
     */
    @ApiOperation("获取地区数据")
    @AutoLog(value = "IndexSearch")
    @RequestMapping(method = RequestMethod.GET, value = "/selectMapData")
    public Result<?> selectMapData(
            @RequestParam(name = "supplierCode", defaultValue = "") String supplierCode) {
        List<Map<String, Object>> mapData = eipPurchaseOrderService.selectMapData(supplierCode);
        return Result.ok(mapData);
    }

    /**
     * 根据采购订单号、省份、工程项目名称模糊查询
     *
     * @param param          参数
     * @param supplierCode   供应商编码
     * @param sellerSignTime 日期
     * @return 地图数据
     */
    @ApiOperation("根据采购订单号、省份、工程项目名称模糊查询")
    @AutoLog(value = "IndexSearch")
    @RequestMapping(method = RequestMethod.GET, value = "/selectByParam")
    public Result<?> selectByParam(
            @RequestParam(name = "param", defaultValue = "") String param,
            @RequestParam(name = "supplierCode", defaultValue = "") String supplierCode,
            @RequestParam(name = "sellerSignTime", defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM-dd") Date sellerSignTime) {
        List<Map<String, Object>> purchaseOrderList = eipPurchaseOrderService.selectByParam(param, supplierCode, sellerSignTime);
        return Result.ok(purchaseOrderList);
    }

    /**
     * 根据采购订单号、省份、工程项目名称模糊查询
     *
     * @param sellerSignTime 日期
     * @return 地图数据
     */
    @ApiOperation("根据采购订单号、省份、工程项目名称模糊查询")
    @AutoLog(value = "IndexSearch")
    @RequestMapping(method = RequestMethod.GET, value = "/selectContractStatisticsByDate")
    public Result<?> selectContractStatisticsByDate(
            @RequestParam(name = "sellerSignTime", defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM-dd") Date sellerSignTime) {
        List<Integer> companyTotal = eipPurchaseOrderService.selectContractStatisticsByDate(sellerSignTime);
        return Result.ok(companyTotal);
    }

    /**
     * 统计公司条数
     *
     * @param supplierCode   供应商编码
     * @param sellerSignTime 日期
     * @return 是否成功
     */
    @ApiOperation("统计公司条数")
    @AutoLog(value = "IndexSearch")
    @RequestMapping(method = RequestMethod.GET, value = "/selectContractProvinceTotal")
    public Result<?> selectContractProvinceTotal(
            @RequestParam(name = "supplierCode", defaultValue = "") String supplierCode,
            @RequestParam(name = "sellerSignTime", defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM-dd") Date sellerSignTime) {
        Map<String, List<Object>> companyTotal = eipPurchaseOrderService.selectContractProvinceTotal(supplierCode, sellerSignTime);
        return Result.ok(companyTotal);
    }

    /**
     * 分页列表查询 采购订单
     *
     * @param eipPurchaseOrder    采购订单
     * @param sellerSignTimeStart 起始时间
     * @param sellerSignTimeEnd   结束时间
     * @param pageNo              当前页页码
     * @param pageSize            每页显示条数
     * @param req                 參數
     * @return
     */
    @ApiOperation("分页列表查询 采购订单")
    @AutoLog(value = "QueryExport")
    @RequestMapping(method = RequestMethod.GET, value = "/list")
    public Result<?> selectForList(
            EipPurchaseOrder eipPurchaseOrder,
            @RequestParam(name = "sellerSignTimeStart", defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM-dd") Date sellerSignTimeStart,
            @RequestParam(name = "sellerSignTimeEnd", defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM-dd") Date sellerSignTimeEnd,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            HttpServletRequest req) {
        //分页参数
        Page<EipPurchaseOrder> page = new Page<>(pageNo, pageSize);
        IPage<EipPurchaseOrder> pageList = eipPurchaseOrderService.selectForList(page, eipPurchaseOrder, sellerSignTimeStart, sellerSignTimeEnd);
        return Result.ok(pageList);

    }

    /**
     * 通过excel导入数据 采购订单
     *
     * @param request  请求
     * @param response 响应
     * @return 是否成功
     */
    @ApiOperation("通过excel导入数据 采购订单")
    @AutoLog(value = "通过excel导入数据 采购订单")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, EipPurchaseOrder.class);
    }

    /**
     * Excel导出 采购订单
     *
     * @param eipPurchaseOrder 采购订单
     * @param request          请求
     * @return 是否成功
     */
    @ApiOperation("Excel导出 采购订单")
    @AutoLog(value = "QueryExport")
    @RequestMapping(method = RequestMethod.GET, value = "/exportXls")
    public ModelAndView exportXls(EipPurchaseOrder eipPurchaseOrder, HttpServletRequest request) {
        return super.exportXls(request, eipPurchaseOrder, EipPurchaseOrder.class, "eip_purchase_order");

    }
}


